//
//  ViewController.swift
//  CMCCIOTSwift
//
//  Created by isoftstone on 2017/4/17.
//  Copyright © 2017年 isoftstone. All rights reserved.
//

import UIKit
import Alamofire

class ViewController: UIViewController {
    var masView : CommonDragMsgView? = nil
     var btn : UIButton?
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.loadData()
        
        btn = UIButton()
        self.view .addSubview(btn!)
        
        btn?.snp.makeConstraints({ (maker) in
            maker.width.height.equalTo(50)
            maker.center.equalTo(self.view)
        })
        
        btn?.setTitle("测试", for: .normal)
        btn?.addTarget(self, action: #selector(btnAction(sender:)), for:.touchUpInside )
        btn?.backgroundColor = UIColor.red
        self.view.backgroundColor = UIColor.white
        
    let maskView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
        maskView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
       // self.view.addSubview(maskView)
        
        self .startLoading()
        let time: TimeInterval = 10.0
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time) {
                
                self.stopLoading()
            }
        
        
        let time1: TimeInterval = 1.0
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time1) {
            
            self.showInfo()
        }
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func loadData() {
        CommonNetWorkKit.shared.post(params: [:]) { (response, result) in
            
        }
    
    }
    func btnAction(sender : UIButton)  {
        self.navigationController?.pushViewController(FirstViewController(), animated:true)
    }
    func startLoading() {
        self.dismiss()
        masView = CommonDragMsgView(frame: self.view.frame)
        masView?.initUI(type: .Loading)
        masView?.setMessage(title: "正在加载.......")
        self.view.addSubview(masView!)
    }
    func stopLoading(){
        
        masView?.stopLoading()
    }
    func dismiss() {
        
        masView?.disMissMessage()
    }
    func showInfo() {
        self .stopLoading()
        masView = CommonDragMsgView(frame: self.view.frame)
        masView?.initUI(type: .Info)
        masView?.setMessage(title: "正在加载.......")
        self.view.addSubview(masView!)
    }
}

